package hu.vpszd.service.impl

import hu.vpszd.entities.User
import hu.vpszd.service.UserDetailsService
import hu.vpszd.services.UserService

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.stereotype.Service

@Service("userDetailsService") 
class UserDetailsServiceImpl implements UserDetailsService {
	@Autowired private UserService userService
	
	@Override
	User getCurrentUser() {
		UserDetails userDetails = (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal()
		User user =  userService.findByUserName(userDetails.username)
		return user
	}
	
	@Override
	String getCurrentUserName() {
		return currentUser.userName
	}
	
	@Override
	String getCurrentUserRealName() {
		return currentUser.realName
	}
	

}